package ym.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ym.mapper.FeedbackMapper;
import ym.pojo.Feedback;
import ym.service.FeedbackService;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class FeedbackServiceImpl implements FeedbackService {
    @Autowired
    private FeedbackMapper feedbackMapper;

    @Override
    public void add(Feedback feedback) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        String timeNow = sdf.format(new Date());
        feedback.setFeedbackTime(timeNow);
        feedbackMapper.insert(feedback);
    }

    @Override
    public void update(Feedback feedback) {
        feedbackMapper.updateById(feedback);
    }

    @Override
    public void delete(Integer id) {
        feedbackMapper.deleteById(id);
    }

    @Override
    public Feedback findById(Integer id) {
        return feedbackMapper.selectById(id);
    }

    @Override
    public List<Feedback> findAll() {
        return feedbackMapper.selectList(null);
    }

    @Override
    public Page<Feedback> search(String search, int page, int size) {
        QueryWrapper<Feedback> queryWrapper = new QueryWrapper<>();
        if (search != null) {
        }
        return feedbackMapper.selectPage(new Page<>(page, size), queryWrapper);
    }
}
